package com.tjcd.project.library_base.common.utils;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * @Author jiangKunKun
 * @CreateDate 2024/10/16
 * @Description 网络校验
 * @SpittingGrooves
 */
public class OuterNetDetectionUtils {
    public static void isUrlAccessible() {
        OkHttpClient client = new OkHttpClient();

        Request request = new Request.Builder()
                .url("https://tmatch-api.sigoran.com")
                .build();

        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                // 在这里处理失败情况
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                // 使用Handler将结果传递回主线程
//                new Handler(Looper.getMainLooper()).post(new Runnable() {
//                    @Override
//                    public void run() {
//                        // 在这里处理结果
//                        LogUtils.e("NetworkUtil", "URL accessible: " + isAccessible);
//                    }
//                });
            }
        });
    }
}
